/*     */ package com.zimbra.cs.zimlet;
/*     */ 
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.io.File;
/*     */ import java.net.InetAddress;
/*     */ import java.net.UnknownHostException;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ZimletConfig
/*     */   extends ZimletMeta
/*     */   implements ZimletConf
/*     */ {
/*     */   public static final String CONFIG_REGEX_VALUE = "ZIMLET_CONFIG_REGEX_VALUE";
/*     */   private Map mGlobalConfig;
/*     */   private Map mSiteConfig;
/*     */   private String mLocalHost;
/*     */   
/*     */   public ZimletConfig(String c)
/*     */     throws ZimletException
/*     */   {
/*  44 */     super(c);
/*     */   }
/*     */   
/*     */   public ZimletConfig(File f) throws ZimletException {
/*  48 */     super(f);
/*     */   }
/*     */   
/*     */   protected void initialize() throws ZimletException {
/*  52 */     this.mGlobalConfig = new HashMap();
/*  53 */     this.mSiteConfig = new HashMap();
/*     */     try {
/*  55 */       this.mLocalHost = InetAddress.getLocalHost().getHostName().toLowerCase();
/*     */     } catch (UnknownHostException uhe) {
/*  57 */       throw ZimletException.INVALID_ZIMLET_CONFIG("cannot figure out hostname on localhost");
/*     */     }
/*     */   }
/*     */   
/*     */   protected void validateElement(Element elem) throws ZimletException {
/*  62 */     if (elem.getName().equals("global")) {
/*  63 */       parseConfig(elem, this.mGlobalConfig);
/*  64 */     } else if (elem.getName().equals("host")) {
/*  65 */       String hostname = elem.getAttribute("name", "").toLowerCase();
/*  66 */       if (this.mLocalHost.equals(hostname)) {
/*  67 */         parseConfig(elem, this.mSiteConfig);
/*     */       } else {
/*  69 */         elem.detach();
/*     */       }
/*     */     } else {
/*  72 */       ZimbraLog.zimlet.warn("unrecognized config element " + elem.getName());
/*     */     }
/*     */   }
/*     */   
/*     */   private void parseConfig(Element elem, Map config) {
/*  77 */     Iterator iter = elem.listElements().iterator();
/*  78 */     while (iter.hasNext()) {
/*  79 */       Element e = (Element)iter.next();
/*  80 */       config.put(e.getAttribute("name", ""), e.getText());
/*     */     }
/*     */   }
/*     */   
/*     */   public String getConfigValue(String key) {
/*  85 */     if (this.mSiteConfig.containsKey(key)) {
/*  86 */       return (String)this.mSiteConfig.get(key);
/*     */     }
/*  88 */     return (String)this.mGlobalConfig.get(key);
/*     */   }
/*     */   
/*     */   public void setRegExValue(String regex) {
/*  92 */     this.mGlobalConfig.put("ZIMLET_CONFIG_REGEX_VALUE", regex);
/*     */   }
/*     */   
/*     */   public Map getGlobalConfig() {
/*  96 */     return this.mGlobalConfig;
/*     */   }
/*     */   
/*     */   public Map getSiteConfig() {
/* 100 */     return this.mSiteConfig;
/*     */   }
/*     */   
/*     */   public String getGlobalConf(String key) {
/* 104 */     return (String)this.mGlobalConfig.get(key);
/*     */   }
/*     */   
/*     */   public String getSiteConf(String key) {
/* 108 */     return (String)this.mSiteConfig.get(key);
/*     */   }
/*     */   
/*     */   public String toXMLString() {
/* 112 */     return this.mTopElement.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/zimlet/ZimletConfig.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */